package com.example.musicaiap.data.database

import androidx.room.Entity
import androidx.room.PrimaryKey

/**
 * 当前播放列表实体
 * 用于记录用户当前正在播放的列表信息和播放状态
 * 整个应用中只有一个当前播放列表记录
 */
@Entity(tableName = "current_playlist")
data class CurrentPlaylistEntity(
    @PrimaryKey
    val id: Int = 1, // 固定为1，确保只有一条记录
    val sourceType: String, // 来源类型：LOCAL(本地)、PLAYLIST(播放列表)、SINGLE(单曲)
    val sourceId: String, // 来源ID：播放列表ID或为空
    val currentSongId: String?, // 当前播放的歌曲ID
    val currentPosition: Long = 0, // 当前播放位置(毫秒)
    val lastPlayedAt: Long = System.currentTimeMillis() // 最后播放时间
) {
    companion object {
        // 来源类型常量
        const val SOURCE_TYPE_LOCAL = "LOCAL"
        const val SOURCE_TYPE_PLAYLIST = "PLAYLIST"
        const val SOURCE_TYPE_SINGLE = "SINGLE"
        
        /**
         * 创建本地音乐播放列表记录
         */
        fun createLocalPlaylist(currentSongId: String? = null): CurrentPlaylistEntity {
            return CurrentPlaylistEntity(
                sourceType = SOURCE_TYPE_LOCAL,
                sourceId = "local_playlist",
                currentSongId = currentSongId
            )
        }
        
        /**
         * 创建普通播放列表记录
         */
        fun createPlaylist(playlistId: String, currentSongId: String? = null): CurrentPlaylistEntity {
            return CurrentPlaylistEntity(
                sourceType = SOURCE_TYPE_PLAYLIST,
                sourceId = playlistId,
                currentSongId = currentSongId
            )
        }
        
        /**
         * 创建单曲播放记录
         */
        fun createSingle(songId: String): CurrentPlaylistEntity {
            return CurrentPlaylistEntity(
                sourceType = SOURCE_TYPE_SINGLE,
                sourceId = "",
                currentSongId = songId
            )
        }
    }
} 